import os

import django
from django.core.exceptions import MultipleObjectsReturned

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
django.setup()


from books.models import Publisher

# p1 = Publisher(name='Apress', address='2855 Telegraph Avenue', city='Berkeley', state_province='CA', country='U.S.A.',
#                website='http://www.apress.com/')
# p1.save()
# p2 = Publisher.objects.create(name="O'Reilly", address='10 Fawcett St.', city='Cambridge', state_province='MA', country='U.S.A.',
#                website='http://www.oreilly.com/')
# publisher_list = Publisher.objects.all()
# print(publisher_list)


# p3 = Publisher(name='Apress', address='2855 Telegraph Avenue', city='Berkeley', state_province='CA', country='U.S.A.',
#                website='http://www.apress.com/')
# print(p3.id)
# p3.save()
# print(p3.id)


# publisher_list = Publisher.objects.filter(name='Apress')
# print(publisher_list)


try:
    p = Publisher.objects.get(name='Apress')
except Publisher.DoesNotExist:
    print ("Apress isn't in the database yet.")
except MultipleObjectsReturned:
    print("many Apress is in the database.")
else:
    print ("Apress is in the database.")
